package com.cy.pj.sys.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.sys.entity.User;
import com.cy.pj.sys.service.UserService;

@RestController
@RequestMapping("/user/")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("doFindPageObjects")
    public JsonResult doFindPageObjects(String username, Long pageCurrent) {
        return new JsonResult(userService.findPageObject(username, pageCurrent));
    }

    @RequestMapping("doValidById")
    public JsonResult doValidById(Long id, Integer valid, String modifiedUser) {
        userService.validById(id, valid, modifiedUser);
        return new JsonResult("update ok");
    }

    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(User user, Integer[] roleIds) {
        userService.saveObject(user, roleIds);
        return new JsonResult("save ok");
    }

    @RequestMapping("doFindObjectById")
    public JsonResult doFindObjectById(Long id) {
        Map<String, Object> map = userService.findObjectById(id);
        return new JsonResult(map);
    }

    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(User user, Integer[] roleIds) {
        userService.updateObject(user, roleIds);
        return new JsonResult("update ok");
    }

}
